using IcsSEMCtrl.Com.Secs;
using IcsSEMCtrl.Service.Logger;
using Lifter.Utility;
using System;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using System.Xml.Linq;

namespace Lifter
{
	internal static class Program
	{
		[STAThread]
		private static void Main()
		{
            bool bCreateNew = false;
			Mutex mutex = new Mutex(true, "Lifter", out bCreateNew);
			if (bCreateNew)
			{
				Application.ThreadException += new ThreadExceptionEventHandler(Program.Application_ThreadException);
				Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
				AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Program.CurrentDomain_UnhandledException);
				BootLoader bootLoader = new BootLoader();
				bootLoader.StartLifter();
                Form mainForm = (Form)SimpleCache.GetObject("FormMain", "LifterMainForm");
                Application.Run(mainForm);
                bootLoader.Close();
			}
			else
			{
				MessageBox.Show("LFTC 已经运行.");
			}
		}
		private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
		{
			LogHelper.loggerError("运行过程中无法处理的异常", (Exception)e.ExceptionObject);
		}
		private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e)
		{
			LogHelper.loggerError("运行过程中线程异常", e.Exception);
		}
	}
}
